/* 
 * Copyright 2008 Rodrigo Reyes <reyes.rr at gmail dot com>
 *
 * Licensed under the Apache License, Version 2.0 (the "License"); you
 * may not use this file except in compliance with the License. You may
 * obtain a copy of the License at
 * 
 * http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
 * implied. See the License for the specific language governing
 * permissions and limitations under the License.
**/
package net.kornr.canvaschart.client.core;

public class Point 
{
	private double m_x, m_y;
	
	public Point(double x, double y)
	{
		m_x = x;
		m_y = y;
	}
	
	public void setX(double x)
	{
		m_x = x;
	}
	
	public void setY(double y)
	{
		m_y = y;
	}
	
	public double getX()
	{
		return m_x;
	}
	
	public double getY()
	{
		return m_y;
	}
	
	public boolean equals(Object o)
	{
		if (o instanceof Point)
		{
			Point other = (Point)o;
			if (other.m_x == this.m_x && other.m_y == this.m_y)
				return true;
		}
		return false;
	}
	
	public void add(Point p)
	{
		m_x += p.m_x;
		m_y += p.m_y;
	}

	public void substract(Point p)
	{
		m_x -= p.m_x;
		m_y -= p.m_y;
	}

	public String toString()
	{
		return "("+format(m_x)+","+format(m_y)+")";
	}
	
	public String format(double d)
	{
		return ""+(int)d+"." + (int)((d*10)%10) + "" + (int)((d*100)%10); 
	}
}
